package thesis.javaclass;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;

import com.sun.mail.handlers.text_html;

import thesis.database.Factory;
import thesis.database.Service;
import thesis.database.ServiceJDBCTemplate;

public class ServiceRequest {
	private String selectedImei; // final imei
	private boolean finished;
	private ArrayList<String> acceptTaxiImeis = null;
	private ArrayList<TempAccept> acceptTaxiNumber;
	private String phoneNumber;
	private String address;
	private int numberOfSeat;
	private ArrayList<Double> coordinate; // coordinate
											// of
											// customer

	public ServiceRequest(ArrayList<TempAccept> acceptedTaxiNumbers) {
		selectedImei = "";
		finished = false;
		acceptTaxiImeis = new ArrayList<String>();
		phoneNumber = "";
		address = "";
		numberOfSeat = -1;
		coordinate = new ArrayList<Double>();
		this.acceptTaxiNumber = acceptedTaxiNumbers;
	}

	public ArrayList<TempAccept> getAcceptTaxiNumber() {
		return acceptTaxiNumber;
	}

	public void setAcceptTaxiNumber(ArrayList<TempAccept> acceptTaxiNumber) {
		this.acceptTaxiNumber = acceptTaxiNumber;
	}

	public String getSelectedImei() {
		return selectedImei;
	}

	public void setSelectedImei(String selectedImei) {
		this.selectedImei = selectedImei;
	}

	public boolean isFinished() {
		return finished;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public void addAcceptImei(String imei) {
		synchronized (this.acceptTaxiImeis) {
			acceptTaxiImeis.add(imei);
		}
	}
	
	public void removeAcceptImei(String imei) {
		synchronized (this.acceptTaxiImeis) {
			acceptTaxiImeis.remove(imei);
		}
	}
	
	

	public void addAcceptedTaxiNumber(String numberPlate) {
		synchronized (this.acceptTaxiNumber) {
			acceptTaxiNumber.add(new TempAccept(numberPlate, address));
		}
	}

	public ArrayList<String> getAcceptTaxiImeis() {
		return acceptTaxiImeis;
	}

	public void setAcceptTaxiImeis(ArrayList<String> acceptTaxiImeis) {
		this.acceptTaxiImeis = acceptTaxiImeis;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getNumberOfSeat() {
		return numberOfSeat;
	}

	public void setNumberOfSeat(int numberOfSeat) {
		this.numberOfSeat = numberOfSeat;
	}

	public ArrayList<Double> getCoordinate() {
		return coordinate;
	}

	public void setCoordinate(ArrayList<Double> coordinate) {
		this.coordinate = coordinate;
	}

	public void updateService(String phone, int status) {
		ServiceJDBCTemplate sericeJDBCTemplate = (ServiceJDBCTemplate) Factory
				.createJDBCTemplate("serviceJDBCTemplate");
		Service service = sericeJDBCTemplate.getServiceByPhone(phone);
		
		if (status == StatusCode.PICKED_UP_STATUS)
			service.setBeginTime(new Timestamp((new Date().getTime())));
		else if (status == StatusCode.FINISH_STATUS)
			service.setEndTime(new Timestamp((new Date().getTime())));
		
		service.setStatus(status);
		sericeJDBCTemplate.update(service);
	}

}
